using ASP;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_myRate : Member, IRequiresSessionState
{
	protected GridView gvList;
	protected string WhoRate = "SalerRate";
	protected string RateType = "0";
	protected string CommentRate = "-1";
	protected string StrWhere = "";
	public string UserName = "";
	public string StrAddress = "";
	public double GoodRate = 0.0;
	public int WeekGoodRate = 0;
	public int WeekNormalRate = 0;
	public int WeekBadRate = 0;
	public int MouthGoodRate = 0;
	public int MouthNormalRate = 0;
	public int MouthBadRate = 0;
	public int SixMGoodRate = 0;
	public int SixMNormalRate = 0;
	public int SixMBadRate = 0;
	public int PreSixMGoodRate = 0;
	public int PreSixMNormalRate = 0;
	public int PreSixMBadRate = 0;
	public int XTotalGoodRate = 0;
	public int XTotalNormalRate = 0;
	public int XTotalBadRate = 0;
	public int CountBuyCredit = 0;
	public double SGoodRate = 0.0;
	public int SWeekGoodRate = 0;
	public int SWeekNormalRate = 0;
	public int SWeekBadRate = 0;
	public int SMouthGoodRate = 0;
	public int SMouthNormalRate = 0;
	public int SMouthBadRate = 0;
	public int SSixMGoodRate = 0;
	public int SSixMNormalRate = 0;
	public int SSixMBadRate = 0;
	public int SPreSixMGoodRate = 0;
	public int SPreSixMNormalRate = 0;
	public int SPreSixMBadRate = 0;
	public int SXTotalGoodRate = 0;
	public int SXTotalNormalRate = 0;
	public int SXTotalBadRate = 0;
	public int CountSalerCredit = 0;
	protected Shop_Product shopProduct = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.shopProduct = new Shop_Product();
			if (base.Request.QueryString["WhoRate"] != null)
			{
				this.WhoRate = base.Request.QueryString["WhoRate"];
			}
			if (base.Request.QueryString["RateType"] != null)
			{
				this.RateType = base.Request.QueryString["RateType"];
			}
			if (base.Request.QueryString["CommentRate"] != null)
			{
				this.CommentRate = base.Request.QueryString["CommentRate"];
			}
			this.ShowUserInfo();
			this.CountRate();
			this.CountTotalSalerCredit();
			this.ShowComment();
		}
	}
	public void ShowUserInfo()
	{
		DataTable dataTable = this.conn.GetDataTable("select * from HL_UserInfo as a,HL_User as b where a.UserID=b.UserID and a.UserID=" + base.user.UserID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			this.UserName = dataTable.Rows[0]["UserName"].ToString();
			this.StrAddress = dataTable.Rows[0]["Address"].ToString();
		}
		else
		{
			DataTable dataTable2 = this.conn.GetDataTable("select UserName from HL_User where UserID=" + base.user.UserID);
			if (dataTable2 != null && dataTable2.Rows.Count > 0)
			{
				this.UserName = dataTable2.Rows[0]["UserName"].ToString();
			}
			dataTable2.Dispose();
		}
		dataTable.Dispose();
	}
	public void CountRate()
	{
		string value = " and ByValuerID=" + base.user.UserID;
		string value2 = " and JustSBCredit=1 ";
		SqlParameter[] array = new SqlParameter[]
		{
			this.conn.CreateSQlParameter("@UserID", SqlDbType.VarChar, value, ParameterDirection.Input),
			this.conn.CreateSQlParameter("@WeekGoodsRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@WeekNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@WeekBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@MouthGoodRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@MouthNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@MouthBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@SixMGoodRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@SixMNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@SixMBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@PreSixMGoodRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@PreSixMNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@PreSixMBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@StrByValuer", SqlDbType.VarChar, value2, ParameterDirection.Input),
			this.conn.CreateSQlParameter("@TotalCredit", SqlDbType.Int, 0, ParameterDirection.Output)
		};
		DataSet dataSet = this.conn.GetDataSet("PR_luoCountUserRate", array);
		if (dataSet != null)
		{
			this.WeekGoodRate = int.Parse(array[1].Value.ToString());
			this.WeekNormalRate = int.Parse(array[2].Value.ToString());
			this.WeekBadRate = int.Parse(array[3].Value.ToString());
			if (array[4].Value != null && array[4].Value.ToString() != "")
			{
				this.MouthGoodRate = int.Parse(array[4].Value.ToString());
			}
			if (array[5].Value != null && array[5].Value.ToString() != "")
			{
				this.MouthNormalRate = int.Parse(array[5].Value.ToString());
			}
			if (array[6].Value != null && array[6].Value.ToString() != "")
			{
				this.MouthBadRate = int.Parse(array[6].Value.ToString());
			}
			if (array[7].Value != null && array[7].Value.ToString() != "")
			{
				this.SixMGoodRate = int.Parse(array[7].Value.ToString());
			}
			if (array[8].Value != null && array[8].Value.ToString() != "")
			{
				this.SixMNormalRate = int.Parse(array[8].Value.ToString());
			}
			if (array[9].Value != null && array[9].Value.ToString() != "")
			{
				this.SixMBadRate = int.Parse(array[9].Value.ToString());
			}
			if (array[10].Value != null && array[10].Value.ToString() != "")
			{
				this.PreSixMGoodRate = int.Parse(array[10].Value.ToString());
			}
			if (array[11].Value != null && array[11].Value.ToString() != "")
			{
				this.PreSixMNormalRate = int.Parse(array[11].Value.ToString());
			}
			if (array[12].Value != null && array[12].Value.ToString() != "")
			{
				this.PreSixMBadRate = int.Parse(array[12].Value.ToString());
			}
			this.XTotalGoodRate = this.SixMGoodRate + this.PreSixMGoodRate;
			this.XTotalNormalRate = this.SixMNormalRate + this.PreSixMNormalRate;
			this.XTotalBadRate = this.SixMBadRate + this.PreSixMBadRate;
			int num = this.XTotalGoodRate + this.XTotalNormalRate + this.XTotalBadRate;
			this.GoodRate = Math.Round(double.Parse(this.XTotalGoodRate.ToString()) / double.Parse(num.ToString()), 2) * 100.0;
			if (this.GoodRate.ToString() == "非数字")
			{
				this.GoodRate = 0.0;
			}
			this.CountBuyCredit = this.shopProduct.BindBuyCrediet(base.user.UserID);
		}
		dataSet.Dispose();
	}
	public void CountTotalSalerCredit()
	{
		string value = " and ByValuerID=" + base.user.UserID;
		string value2 = " and JustSBCredit=0 ";
		SqlParameter[] array = new SqlParameter[]
		{
			this.conn.CreateSQlParameter("@UserID", SqlDbType.VarChar, value, ParameterDirection.Input),
			this.conn.CreateSQlParameter("@WeekGoodsRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@WeekNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@WeekBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@MouthGoodRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@MouthNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@MouthBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@SixMGoodRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@SixMNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@SixMBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@PreSixMGoodRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@PreSixMNormalRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@PreSixMBadRate", SqlDbType.Int, 0, ParameterDirection.Output),
			this.conn.CreateSQlParameter("@StrByValuer", SqlDbType.VarChar, value2, ParameterDirection.Input),
			this.conn.CreateSQlParameter("@TotalCredit", SqlDbType.Int, 0, ParameterDirection.Output)
		};
		DataSet dataSet = this.conn.GetDataSet("PR_luoCountUserRate", array);
		if (dataSet != null)
		{
			this.SWeekGoodRate = int.Parse(array[1].Value.ToString());
			this.SWeekNormalRate = int.Parse(array[2].Value.ToString());
			this.SWeekBadRate = int.Parse(array[3].Value.ToString());
			if (array[4].Value != null && array[4].Value.ToString() != "")
			{
				this.SMouthGoodRate = int.Parse(array[4].Value.ToString());
			}
			if (array[5].Value != null && array[5].Value.ToString() != "")
			{
				this.SMouthNormalRate = int.Parse(array[5].Value.ToString());
			}
			if (array[6].Value != null && array[6].Value.ToString() != "")
			{
				this.SMouthBadRate = int.Parse(array[6].Value.ToString());
			}
			if (array[7].Value != null && array[7].Value.ToString() != "")
			{
				this.SSixMGoodRate = int.Parse(array[7].Value.ToString());
			}
			if (array[8].Value != null && array[8].Value.ToString() != "")
			{
				this.SSixMNormalRate = int.Parse(array[8].Value.ToString());
			}
			if (array[9].Value != null && array[9].Value.ToString() != "")
			{
				this.SSixMBadRate = int.Parse(array[9].Value.ToString());
			}
			if (array[10].Value != null && array[10].Value.ToString() != "")
			{
				this.SPreSixMGoodRate = int.Parse(array[10].Value.ToString());
			}
			if (array[11].Value != null && array[11].Value.ToString() != "")
			{
				this.SPreSixMNormalRate = int.Parse(array[11].Value.ToString());
			}
			if (array[12].Value != null && array[12].Value.ToString() != "")
			{
				this.SPreSixMBadRate = int.Parse(array[12].Value.ToString());
			}
			this.SXTotalGoodRate = this.SSixMGoodRate + this.SPreSixMGoodRate;
			this.SXTotalNormalRate = this.SSixMNormalRate + this.SPreSixMNormalRate;
			this.SXTotalBadRate = this.SSixMBadRate + this.SPreSixMBadRate;
			int num = this.SXTotalGoodRate + this.SXTotalNormalRate + this.SXTotalBadRate;
			this.SGoodRate = Math.Round(double.Parse(this.SXTotalGoodRate.ToString()) / double.Parse(num.ToString()), 2) * 100.0;
			if (this.SGoodRate.ToString() == "非数字")
			{
				this.SGoodRate = 0.0;
			}
			this.CountSalerCredit = this.shopProduct.BindSaleCrediet(base.user.UserID);
		}
		dataSet.Dispose();
	}
	public string Levelrate(string RateScore)
	{
		string result = "<img src='../Images/CreditImage/rate-ok.gif'/>好评";
		if (RateScore != null)
		{
			if (!(RateScore == "0"))
			{
				if (RateScore == "-1")
				{
					result = "<img src='../Images/CreditImage/rate-bad.gif'/>差评";
				}
			}
			else
			{
				result = "<img src='../Images/CreditImage/rate-normal.gif'/>中评";
			}
		}
		return result;
	}
	public void ShowComment()
	{
		this.StrQuery();
		DataTable dataTable = this.conn.GetDataTable(this.StrWhere);
		this.gvList.DataSource = dataTable;
		this.gvList.DataBind();
		if (this.WhoRate == "SalerRate")
		{
			for (int i = 0; i < this.gvList.Rows.Count; i++)
			{
				int count = this.gvList.Columns.Count;
				this.gvList.HeaderRow.Cells[count - 1].Visible = false;
				this.gvList.Rows[i].Cells[count - 1].Visible = false;
			}
		}
		else
		{
			if (this.WhoRate == "BuyerRate")
			{
				for (int i = 0; i < this.gvList.Rows.Count; i++)
				{
					int count = this.gvList.Columns.Count;
					this.gvList.HeaderRow.Cells[count - 1].Visible = false;
					this.gvList.Rows[i].Cells[count - 1].Visible = false;
				}
			}
			else
			{
				for (int i = 0; i < this.gvList.Rows.Count; i++)
				{
					int count = this.gvList.Columns.Count;
					this.gvList.HeaderRow.Cells[count - 1].Visible = true;
					this.gvList.Rows[i].Cells[count - 1].Visible = true;
					HiddenField hiddenField = (HiddenField)this.gvList.Rows[i].FindControl("hfCreditScore");
					LinkButton linkButton = (LinkButton)this.gvList.Rows[i].FindControl("lbtUpdateGood");
					LinkButton linkButton2 = (LinkButton)this.gvList.Rows[i].FindControl("lbtDel");
					if (hiddenField != null)
					{
						string value = hiddenField.Value;
						if (!string.IsNullOrEmpty(value))
						{
							if (value.Trim() == "1")
							{
								if (linkButton != null)
								{
									linkButton.Visible = false;
								}
								if (linkButton2 != null)
								{
									linkButton2.Visible = false;
								}
							}
							else
							{
								if (linkButton != null)
								{
									linkButton.Visible = true;
								}
								if (linkButton2 != null)
								{
									linkButton2.Visible = true;
								}
							}
						}
					}
				}
			}
		}
	}
	public void StrQuery()
	{
		string str = "";
		string str2 = "";
		if (this.WhoRate == "SalerRate")
		{
			this.StrWhere = this.StrWhere + "select * from HLMall_Credit as a,HLShop_Order as b where a.OrderFormNum=b.OrderFormNum and a.ByValuerID=b.UserID and a.ByValuerID=" + base.user.UserID;
		}
		else
		{
			if (this.WhoRate == "BuyerRate")
			{
				object strWhere = this.StrWhere;
				this.StrWhere = string.Concat(new object[]
				{
					strWhere,
					"select * from HLMall_Credit as a,HLShop_Order as b where a.OrderFormNum=b.OrderFormNum and a.ByValuerID=b.SalerID and a.ByValuerID=",
					base.user.UserID,
					" "
				});
			}
			else
			{
				this.StrWhere = this.StrWhere + "select * from HLMall_Credit where ValuerID=" + base.user.UserID;
			}
		}
		string text = this.RateType;
		if (text != null)
		{
			if (!(text == "1"))
			{
				if (!(text == "2"))
				{
					if (text == "3")
					{
						str = " and CreditScore=-1";
					}
				}
				else
				{
					str = " and CreditScore=0";
				}
			}
			else
			{
				str = " and CreditScore=1";
			}
		}
		this.StrWhere += str;
		text = this.CommentRate;
		if (text != null)
		{
			if (!(text == "1"))
			{
				if (text == "0")
				{
					str2 = " and (Comment='' or Comment is null)";
				}
			}
			else
			{
				str2 = " and Comment<>'' and Comment is not null";
			}
		}
		this.StrWhere += str2;
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string text = e.CommandName.ToString();
		string text2 = e.CommandArgument.ToString();
		if (!string.IsNullOrEmpty(text2))
		{
			string sql = "select * from HLMall_Credit where CreditID=" + text2 + " and DATEDIFF(DD,CreateTime,GETDATE())<=30";
			DataTable dataTable = this.conn.GetDataTable(sql);
			if (dataTable.Rows.Count > 0)
			{
				if (text.Trim() == "delInfo")
				{
					string sql2 = "delete HLMall_Credit where CreditID=" + text2;
					int num = this.conn.Execute(sql2);
					if (num > 0)
					{
						this.WriteSuccessMsg("", "评价信息删除成功！", "Shop_myRate.aspx?WhoRate=" + this.WhoRate);
					}
					else
					{
						this.WriteErrMsg("", "评价信息删除失败！", "Shop_myRate.aspx?WhoRate=" + this.WhoRate);
					}
				}
				else
				{
					if (text.Trim() == "upInfo")
					{
						if (dataTable.Columns.Contains("OrderFormNum"))
						{
							if (dataTable.Rows[0]["OrderFormNum"] != DBNull.Value)
							{
								string text3 = dataTable.Rows[0]["OrderFormNum"].ToString();
								if (!string.IsNullOrEmpty(text3))
								{
									string url = "CreditComment.aspx?OrderFormNum=" + text3 + "&Action=editinfo&CreditInfoID=" + text2;
									base.Response.Redirect(url);
								}
							}
						}
					}
				}
			}
			else
			{
				this.WriteErrMsg("", "评价信息已超过30天!", "Shop_myRate.aspx?WhoRate=" + this.WhoRate);
			}
		}
		this.ShowComment();
	}
}
